package com.wysql.thread.deadlock;

public class DeadLock {

    public static void main(String[] args) {

        Object objectA = new Object();
        Object objectB = new Object();

        new Thread(() -> {
            int a = 0;
            while (true) {
                synchronized (objectA){
                    System.out.println("A1出发");
                    synchronized (objectB){
                        System.out.println("B1出发");
                        a++;
                        System.err.println(a);
                    }
                }
            }
        }).start();

        new Thread(() -> {
            while (true) {
                synchronized (objectB){
                    System.out.println("B2出发");
                    synchronized (objectA){
                        System.out.println("A2出发");
                    }
                }
            }
        }).start();

    }
}
